package reposit

import (
	"errors"
	"fmt"
	"github.com/jinzhu/gorm"
	"sbd_zgqx/inits"
	"sbd_zgqx/models"
)

type ProvinceReposit struct {
	Db inits.Database
}

func (repo *ProvinceReposit) IsProvinceOne(area string) (bool, error) {
	fmt.Println(area)
	db := repo.Db.DB
	isProvince := &models.Province{}
	if !errors.Is(db.Raw("select * from province where area=?", area).Scan(&isProvince).Error, gorm.ErrRecordNotFound) {
		return false, errors.New("登记证号已存在！")
	}
	return true, nil
}
func (repo *ProvinceReposit) InsertProvinceOne(isProvince models.Province) (bool, error) {
	db := repo.Db.DB
	err := db.Table("province").Create(isProvince).Error

	if err != nil {
		return false, errors.New("添加 地区 失败")
	}
	return true, nil
}
